home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 May / Disc 2 / PCU0503CD2.iso / Crystal / 3rdparty / JavaVM / Plug-in / jplugin.exe / jaws.jar / sun / plugin / ClassLoaderInfo.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-06-22  |  2.2 KB  |  85 lines

  1. package sun.plugin;
  2.  
  3. import java.net.URL;
  4. import java.util.Hashtable;
  5. import sun.applet.AppletPanel;
  6.  
  7. class ClassLoaderInfo {
  8.    private static Hashtable infos = new Hashtable();
  9.    private URL codebase;
  10.    private int references = 0;
  11.    private Hashtable jars;
  12.    private boolean locked;
  13.    private static boolean initialized;
  14.    private static boolean cacheJars = true;
  15.  
  16.    private static synchronized void initialize() {
  17.       if (!initialized) {
  18.          initialized = true;
  19.          int var0 = Integer.getInteger("javaplugin.jar.cache.size", 100);
  20.          if (var0 > 0) {
  21.             cacheJars = true;
  22.             System.err.println("JAR cache enabled.");
  23.          } else {
  24.             cacheJars = false;
  25.             System.err.println("JAR cache disabled.");
  26.          }
  27.       }
  28.    }
  29.  
  30.    static synchronized ClassLoaderInfo find(AppletPanel var0) {
  31.       initialize();
  32.       URL var1 = var0.getCodeBase();
  33.       ClassLoaderInfo var2 = (ClassLoaderInfo)infos.get(var1);
  34.       if (var2 == null) {
  35.          var2 = new ClassLoaderInfo(var1);
  36.          infos.put(var1, var2);
  37.       }
  38.  
  39.       return var2;
  40.    }
  41.  
  42.    synchronized void addReference() {
  43.       ++this.references;
  44.    }
  45.  
  46.    synchronized void removeReference() {
  47.       --this.references;
  48.       if (this.references < 0) {
  49.          throw new Error("negative ref count???");
  50.       } else {
  51.          if (this.references == 0 && !cacheJars) {
  52.             infos.remove(this.codebase);
  53.             AppletPanel.flushClassLoader(this.codebase);
  54.          }
  55.  
  56.       }
  57.    }
  58.  
  59.    private ClassLoaderInfo(URL var1) {
  60.       this.codebase = var1;
  61.       this.jars = new Hashtable();
  62.    }
  63.  
  64.    synchronized void addJar(String var1) {
  65.       this.jars.put(var1, var1);
  66.    }
  67.  
  68.    synchronized boolean hasJar(String var1) {
  69.       return this.jars.get(var1) != null;
  70.    }
  71.  
  72.    public final synchronized void lock() throws InterruptedException {
  73.       while(this.locked) {
  74.          this.wait();
  75.       }
  76.  
  77.       this.locked = true;
  78.    }
  79.  
  80.    public final synchronized void unlock() {
  81.       this.locked = false;
  82.       this.notifyAll();
  83.    }
  84. }
  85.